import { makeAutoObservable } from 'mobx'
import { createContext, useContext } from 'react'


export interface AppConfig {
    DefaultImageHorizontal: string 
    DefaultImageVertical: string 
    ForeverOfficialDomain: string 
    MHJsonAddress: string 
    OfficialEmailConfig: string 
    OnlineCustomerUrl: string 
    PopAdList: [] 
    SPJsonAddress: string 
    WebSiteFileDoMain: string 
    XSJsonAddress: string 
}
class GlobalStore {
    constructor() {
        makeAutoObservable(this)
        this.changeTheme = this.changeTheme.bind(this)
        this.changeLanguage = this.changeLanguage.bind(this)
        this.changeAppConfig = this.changeAppConfig.bind(this)
        this.changeToastKey = this.changeToastKey.bind(this)
        this.changeAutoLogin = this.changeAutoLogin.bind(this)
    }

    /** 主题肤色 */
    theme = 'red'

    /** 语言 */
    language: string = 'zhHK'
    
    /** toast key */
    toastKey: string = ''
    
    /** 是否自动登录 */
    autologin: boolean = false
    
    /** config */
    appConfig: AppConfig | null = null

    changeTheme(te: string) {
        this.theme = te
    }

    changeLanguage(l: string) {
        this.language = l;
    }
    
    changeAppConfig(con: AppConfig) {
        this.appConfig = {...con}
    }
    
    changeToastKey(tKey: string) {
        this.toastKey = tKey;
    }
    
    changeAutoLogin(b: boolean) {
        this.autologin = b;
    }
}

const globalContent = createContext(new GlobalStore())

export const useGlobalStore = () => useContext(globalContent)
